package com.ayu.shortlink.settlement.controller;

import com.ayu.shortlink.settlement.common.convention.result.Result;
import com.ayu.shortlink.settlement.common.convention.result.Results;
import com.ayu.shortlink.settlement.convert.PayRequestConvert;
import com.ayu.shortlink.settlement.dto.base.PayRequest;
import com.ayu.shortlink.settlement.dto.req.PayCommand;
import com.ayu.shortlink.settlement.dto.resp.PayRespDTO;
import com.ayu.shortlink.settlement.service.UserPayService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户支付相关的控制器
 */
@RestController
@RequiredArgsConstructor
public class UserPayController {
    private final UserPayService userPayService;

    /**
     * 创建用户支付订单
     */
    @PostMapping("/api/short-link/settlement/v1/user-pay/create")
    public Result<PayRespDTO> createUserPay(@RequestBody PayCommand requestParam){
        PayRequest request = PayRequestConvert.command2PayRequest(requestParam);
        return Results.success(userPayService.createUserPay(request));
    }

    /**
     * 支付宝回调接口
     */
    @PostMapping("/api/short-link/settlement/v1/user-pay/alipay/notify")
    public Result<String> alipayNotify(HttpServletRequest request){
        return Results.success(userPayService.alipayNotify(request));
    }
}
